package com.hualan.sfzy.service.psyc.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.CounselorComment;
import com.hualan.sfzy.entity.PsycTestClassification;

import com.hualan.sfzy.mapper.psyc.PsycTestClassificationMapper;
import com.hualan.sfzy.service.psyc.PsycTestClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PsycTestClassificationServiceImpl implements PsycTestClassificationService {
    @Autowired
    private PsycTestClassificationMapper mapper;
    @Override
    public int add(PsycTestClassification entity) {
        return mapper.insert( entity);
    }

    @Override
    public int edit(PsycTestClassification entity) {
        return mapper.update( entity);
    }

    @Override
    public int remove(Integer id) {
        return mapper.delete( id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return mapper.deleteBatch(ids);
    }

    @Override
    public List<PsycTestClassification> find() {
        return mapper.select(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, PsycTestClassification entity) {
        // 开启分页
        PageHelper.startPage(pageNum, pageSize);
        List<PsycTestClassification> list = mapper.select(entity); // 当前页数据
        PageInfo<PsycTestClassification> pageInfo = new PageInfo<>(list); // 分页信息对象
        Map<String, Object> map = new HashMap<>();
        // map存储当前页数据、总页数、总记录数
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }

    @Override
    public PsycTestClassification findById(Integer id) {
        return mapper.selectById( id);
    }
}
